package com.bihu.bihudemo.task;

import com.bihu.bihudemo.service.CommentLikeService;
import com.bihu.bihudemo.service.CommentService;
import com.bihu.bihudemo.service.RedisService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;

/**
 * 点赞定时任务,每隔一段时就将缓存的数据同步到数据库
 */
@Service
public class LikeTask {

    @Resource
    CommentLikeService commentLikeService;

    @Autowired
    RedisService redisService;




    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Scheduled(cron = "0 0/1 * * * ?")
    public void hello(){

        System.out.println("每隔一分钟就被执行点赞数据持久化到数据库的操作：");
        commentLikeService.likedInfoFromRedis2DB();
        commentLikeService.likedNumFromRedis2DB();
        //同步文章的阅读信息
        redisService.SynViewNum();

    }
}
